package com.mayblackcat.dy.service.impl;

import com.mayblackcat.dy.FrontEndData.AjaxResult;
import com.mayblackcat.dy.dao.VideoDao;
import com.mayblackcat.dy.entity.Video;
import com.mayblackcat.dy.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
public class VideoServiceImpl implements
        VideoService {

    @Autowired
    private VideoDao videoDao;


    //搜索
    @Override
    public AjaxResult searchHotVideo(String keyword) {
        AjaxResult hotVideo=null;
        if(keyword.isEmpty()||keyword==""){
            return new AjaxResult(AjaxResult.Type.WARN,"无搜索记录~");
        }


        if(videoDao.searchHotVideo(keyword)!=null){
            List<Video> listHotVideo=videoDao.searchHotVideo(keyword);
            hotVideo=new AjaxResult(AjaxResult.Type.SUCCESS,"success",listHotVideo);
        }else{
            hotVideo=new AjaxResult(AjaxResult.Type.WARN,"warn",null);
        }

        return hotVideo;
    }


    //推荐算法
    @Override
    public List<Video> searchRecommendVideo() {
        List<Video> videoList=null;

        videoList=videoDao.searchRecommendVideo();

        return videoList;
    }


    @Transactional
    public void updateLikesById(Video video) {
        videoDao.updateLikesById(video);
    }


}
